package wangjg.coco.module;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import wangjg.mda.context.FileSystemModelContext;
import wangjg.mda.gen.Generator;
import wangjg.mda.model.obj.Model;

public class Model2SourceProcessor extends Generator {
	private boolean separate = false;
	private String targetCharset = "utf-8";
	private List<String> modelFileList;
	
	private FileSystemModelContext ctx = new FileSystemModelContext();
	
	public Model2SourceProcessor() {
	}
	
	public void process(){
		List<Model> modelList = this.getModelList();
		this.pretreatment(modelList);
		this.setTool("CONTEXT", ctx);
		this.gen(modelList, separate);
		System.out.println("Over.");
	}
	
	private List<Model> getModelList(){
		List<Model> modelList = new ArrayList<Model>();
		for(String filePath:modelFileList){
			try {
				Model model = ctx.loadModel(new File(filePath));
				modelList.add(model);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return modelList;
	}

	public void setSeparate(boolean separate) {
		this.separate = separate;
	}

	public void setModelFileList(List<String> fileList) {
		this.modelFileList = fileList;
	}
	
	public void setModelDir(String modelDir){
		List<String> ctxDirList = new ArrayList<String>();
		ctxDirList.add(modelDir);
		ctx.setDirList(ctxDirList);
	}

	public void setSrcCharset(String srcCharset) {
		ctx.setCharset(srcCharset);
	}

	public void setTargetCharset(String targetCharset) {
		this.targetCharset = targetCharset;
	}

}
